package com.chlitina.store.modules.sms.quartz;

import java.util.Calendar;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import com.chlitina.store.modules.sms.entity.SmsSendQueue;
import com.chlitina.store.modules.sms.service.SmsSendQueueService;
import com.chlitina.store.modules.sms.utils.SmsUtils;


@Component
public abstract class ManualSmsQueueGenrate {

	@Autowired
	protected SmsSendQueueService smsSendQueueService;
	
	
	protected Calendar cal = null;
	protected static int intervalTime = 1;//生成短信的间隔时间
	protected static int  SMS_MAXNUM = 64;//一条短信最长64个字符.汉字\英文
	
	protected String phone;//电话号码
	protected String content;//发送内容
	
	
	public ManualSmsQueueGenrate() {
	}
	abstract public void saveQueue();
	public boolean generate(){
		saveQueue();
		createDetail();
		createQueue();
		timeIncrease();
		return true;
	};
	/**
	 * 验证系统短信余额 
	 * @param storeId
	 * @return
	 */
	public boolean volidate(){
		//验证系统短信余额
		String reamin = SmsUtils.getSmsTotalReamin();
		if ("".equals(reamin)) {
			return true;
		}
		return false;
	}
	
	/**
	 * 生成日志信息
	 */
	abstract public Long createLog();
	
	/**
	 * 生成描述信息
	 */
	abstract public void createDetail();
	
	/**
	 * 生成发送信息
	 */
	public void createQueue(){
		SmsSendQueue sms = new SmsSendQueue();
		sms.setMobile(phone);
		sms.setPlanSendTime(cal.getTime());
		sms.setContent(content);
		smsSendQueueService.save(sms);
	} 
	
	abstract public void setPlanSendTime(Calendar cal);
	public void timeIncrease(){
		cal.add(Calendar.SECOND, intervalTime);
	}
	
	public int getSmsNum(int length){
		return length / SMS_MAXNUM + 1;
	}
	
}
